#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e5+10;
int n;
vector<int> bian[N];
struct segment_tree{
    int ls[N*60],rs[N*60];
    long long sum[N*60];
    int pcnt;
    void update(int &now,int cop,int l,int r,int p,int v){
        now = ++pcnt;
        ls[now] = ls[cop];  
        rs[now] = rs[cop];
        sum[now] = sum[cop] + v;
        if(l == r){
            return;
        }
        int mid = (l + r)/2;
        if(p <= mid){
            update(ls[now],ls[cop],l,mid,p,v);
        }else{
            update(rs[now],rs[cop],mid+1,r,p,v);
        }
    }
    long long qs(int now,int l,int r,int x,int y){
        if(x <= l && r <= y){
            return sum[now];
        }
        int mid = (l + r)/2;
        long long su = 0;
        if(x <= mid){
            su += qs(ls[now],l,mid,x,y);
        }
        if(mid < y){
            su += qs(rs[now],mid+1,r,x,y);
        }
        return su;
    }
}sg;
int mdep[N],son[N];
int fath[N];
int dep[N];
int siz[N];
void dfs(int x,int fa){    
    fath[x] = fa;
    dep[x] = dep[fa] + 1;
    siz[x] = 1;
    for(int v : bian[x]){
        if(v == fa)continue;
        dfs(v,x);
        mdep[x] = max(mdep[v] + 1,mdep[x]);
        if(mdep[v] > mdep[son[x]]){
            son[x] = v;
        }
        siz[x] += siz[v];     
    }
}
int dfn[N],dft,rnk[N];
int rot[N];
void dfs1(int x){
    dfn[x] = ++dft;
    rnk[dft] = x; 
    if(son[x]){
        dfs1(son[x]);
        rot[x] = rot[son[x]];
        sg.update(rot[x],rot[x],1,n,dfn[x] + 1,siz[son[x]] - 1);
    }
    for(int v : bian[x]){
        if(v == son[x] || v == fath[x]){
            continue;
        }
        dfs1(v);
        sg.update(rot[x],rot[x],1,n,dfn[x] + 1,siz[v] - 1);
        for(int i = 2;i <= mdep[v];i++){
            sg.update(rot[x],rot[x],1,n,dfn[x] + i,sg.qs(rot[v],1,n,dfn[v] + i - 1,dfn[v] + i - 1));
        }
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int q;
    cin>>n>>q;
    for(int i = 1;i < n;i++){
        int u,v;
        cin>>u>>v;
        bian[u].push_back(v);
        bian[v].push_back(u);
    }
    dfs(1,0);
    dfs1(1);
    for(int i = 1;i<=q;i++){
        int p,k;
        cin>>p>>k;
        cout<<sg.qs(rot[p],1,n,dfn[p],dfn[p] + min(k,mdep[p] - 1)) + 1ll*(siz[p] - 1)*(min(dep[p] - 1,k))<<'\n';
    }
}